﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		
		termId = event.getArg("TermID", event.getArg("TID"));
		
		/* 学籍相关信息 */
		studentId = sessionAdvice.getAutherUserID();
		
		passArgs = structNew();
		structInsert( passArgs, "TID", termId, true);
		structInsert( passArgs, "STU", studentId, true);
		structInsert( passArgs, "TabID", "labChoosenType", true);

		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		chooseProp = getProperty("serviceFactory").getBean("choosePropertyAdvice");

		choosenArray = [];
		
		preCharged = 0;
		payCharged = 0;
		paySecondCharged = 0;
		payAssistCharged = 0;
		
		chargeArray = [];
		
		chargePerCredit = 0;
		chargeRetakenPerCredit = 0;
		chargeSecondaryPerCredit = 0;
		chargeAssistPerCredit = 0;

		if ( len(studentId) and len(termId) ) {
			
			/* 正常专业学费 */
			sql = "SELECT regular, resit FROM t_charge 
					WHERE 
						EXISTS (
							SELECT 1 FROM t_student 
							INNER JOIN t_class ON t_class.cls_id = t_student.cls_id 
							WHERE 
								stu_id = :studentId 
								AND 
								t_class.grade = t_charge.grade 
								AND 
								t_class.sbj_id = t_charge.sbj_id ) ";
			
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );

			rs_charge = queryObj.execute( sql=sql ).getResult();

			if ( rs_charge.recordCount ) {
				chargePerCredit = rs_charge.regular;
				chargeRetakenPerCredit = rs_charge.resit;
			}
			
			/* 辅修专业学费 */
			sql = "SELECT assist FROM t_charge 
					WHERE 
						EXISTS (
							SELECT 1 FROM t_student_secsubject 
							WHERE 
								stu_id = :studentId 
								AND 
								t_student_secsubject.grade = t_charge.grade 
								AND 
								t_student_secsubject.sbj_id = t_charge.sbj_id ) ";
			
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );

			rs_charge_ast = queryObj.execute( sql=sql ).getResult();


			if ( rs_charge_ast.recordCount ) {
				chargeAssistPerCredit = rs_charge_ast.assist;
			}
			
			/* 双学位专业学费 */
			sql = "SELECT secondary FROM t_charge 
					WHERE 
						EXISTS (
							SELECT 1 FROM t_student_secdegree 
							WHERE 
								stu_id = :studentId 
								AND 
								t_student_secdegree.grade = t_charge.grade 
								AND 
								t_student_secdegree.sbj_id = t_charge.sbj_id ) ";
			
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );

			rs_charge_sec = queryObj.execute( sql=sql ).getResult();


			if ( rs_charge_sec.recordCount ) {
				chargeSecondaryPerCredit = rs_charge_sec.secondary;
			}

			/* 读取学生的已选课程 */
			sql = "SELECT 
					t_course.cid, t_course.course_name, t_course.course_credit, 
					t_choose_turn.turn, 
					task_type, scc_id, st, retaking, 
					choose_time, choose_prop, task_id, 
					charge_time 
					FROM t_student_course 
					INNER JOIN t_course ON t_course.cid = t_student_course.cid
					INNER JOIN t_choose_turn ON t_choose_turn.ct = t_student_course.ct 
					INNER JOIN t_course_prop ON t_course_prop.prop_id = t_student_course.prop_id 
					WHERE 
						stu_id = :studentId 
						AND 
						term_id = :termId 
					ORDER BY 
						retaking, st, task_type, t_course.course_name";
		
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );

			rs_choosen = queryObj.execute( sql=sql ).getResult();

		}
		
	</cfscript>
</cfsilent>

<cfif rs_choosen.recordCount >
	<table class="UIEditable">
		<thead>
			<tr>
				<td width="18"></td>
				<td>课程</td>
				<td>学分</td>
				<td>开课类别</td>
				<td>修读方式</td>
				<td>重修</td>
				<td>学费</td>
				<td>结算时间</td>
				<td width="18"></td>
			</tr>
		</thead>
		<tbody>
			<cfset row = 0 />
			<cfloop query="rs_choosen">
				<cfset row++ />
				
				<!--- 检查教学任务 --->
				<cfscript>
					switch ( rs_choosen.task_type ) { 
						
						case "P":
							sql = "SELECT 1 FROM t_task t 
									INNER JOIN t_teacher ON t_teacher.tch_id = t.tch_id 
									INNER JOIN t_campus ON t_campus.campus_id = t.campus_id
									WHERE tsk_id = :taskId ";
							break;
						
						case "C":
							sql = "SELECT 1 FROM t_common_task t 
									INNER JOIN t_teacher ON t_teacher.tch_id = t.tch_id 
									INNER JOIN t_campus ON t_campus.campus_id = t.campus_id
									WHERE tsk_id = :taskId ";
							break;
						
						case "T":
							sql = "SELECT 1 FROM t_sport_task t 
									INNER JOIN t_teacher ON t_teacher.tch_id = t.tch_id 
									INNER JOIN t_campus ON t_campus.campus_id = t.campus_id
									WHERE tsk_id = :taskId ";
							break;
						
						case "R":
							sql = "SELECT 1 FROM t_reopen_task t 
									INNER JOIN t_teacher ON t_teacher.tch_id = t.tch_id 
									INNER JOIN t_campus ON t_campus.campus_id = t.campus_id
									WHERE tsk_id = :taskId ";
							break;
						
					}
					
					queryObj = new Query( datasource=application.dnsSlave );
					queryObj.addParam( name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_char" );

					rs_task = queryObj.execute( sql=sql ).getResult();
					
				</cfscript>
				
				<cfif rs_task.recordCount>
					<!--- 如果教学任务有效 --->
				
					<cfset structInsert( passArgs, "SCC", rs_choosen.scc_id, true) />

					<cfset chooseProp.parseProperty( rs_choosen.choose_prop ) />
					<tr class="editRows <cfif rs_choosen.st eq "R">noticeRow1</cfif> <cfif rs_choosen.st eq "F">noticeRow2</cfif>">
						<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
						<td><cfoutput>#rs_choosen.course_name#</cfoutput></td>
						<td><span class="numeric"><cfoutput>#numberFormat(rs_choosen.course_credit, '_.__')#</cfoutput></span></td>
						<td><cfoutput>#dictAdvice.getTaskType( rs_choosen.task_type )#</cfoutput></td>
						<td><cfoutput>#dictAdvice.getStudyType( rs_choosen.st )#</cfoutput></td>
						<td><cfif rs_choosen.retaking eq "1">是</cfif></td>

						<td>
							<cfset thisCharge = 0 />
							<cfswitch expression="#rs_choosen.st#">
								<cfcase value="N,F,E">
									<!--- 正常 或 补修 --->
									<cfset thisCharge = chargePerCredit*rs_choosen.course_credit />
									<cfset preCharged = preCharged + thisCharge />
									<span class="numeric bold"><cfoutput>#numberFormat(thisCharge, "_.__")#</cfoutput></span>
								</cfcase>
								<cfcase value="R">
									<!--- 重修 --->
									<cfset thisCharge = chargeRetakenPerCredit*rs_choosen.course_credit />
									<cfset payCharged = payCharged + thisCharge />
									<span class="numeric bold"><cfoutput>#numberFormat(chargeRetakenPerCredit*rs_choosen.course_credit, "_.__")#</cfoutput></span>
								</cfcase>
								<cfcase value="S">
									<!--- 双学位 --->
									<cfset thisCharge = chargeSecondaryPerCredit*rs_choosen.course_credit />
									<cfset paySecondCharged = paySecondCharged + thisCharge />
									<span class="numeric bold"><cfoutput>#numberFormat(chargeSecondaryPerCredit*rs_choosen.course_credit, "_.__")#</cfoutput></span>
								</cfcase>
								<cfcase value="A">				
									<!--- 辅修 --->
									<cfset thisCharge = chargeAssistPerCredit*rs_choosen.course_credit />
									<cfset payAssistCharged = payAssistCharged + thisCharge />
									<span class="numeric bold"><cfoutput>#numberFormat(chargeAssistPerCredit*rs_choosen.course_credit, "_.__")#</cfoutput></span>
								</cfcase>
							</cfswitch>
						</td>
						
						<td>
							<cfif rs_choosen.choose_time neq rs_choosen.charge_time>
								<span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString(rs_choosen.charge_time, 'YYYY/MM/DD')#</cfoutput></span>
							</cfif>
						</td>
						
						<td>
							<cfif chooseProp.getPrePaid()>
									<span title="从预交学费中扣除" class="stat charged"></span>
								<cfelseif chooseProp.getPaid()>
									<span title="已结算" class="stat checked"></span>
								<cfelse>
									<span title="未结算" class="stat settime"></span>
							</cfif>
						</td>
					</tr>

					<cfelse>
					<!--- 如果教学任务无效 则直接删除错误的选课记录 --->
				</cfif>

			</cfloop>
		</tbody>	
	</table>
	
	<cfset colspan = 4 />
	<cfif payCharged gt 0><cfset colspan += 2 /></cfif>
	<cfif paySecondCharged gt 0><cfset colspan += 2 /></cfif>
	<cfif payAssistCharged gt 0><cfset colspan += 2 /></cfif>
	
	<table class="UIEditable">
		<tbody>	
			<tr class="breakRowsBold">
				<td colspan="<cfoutput>#colspan#</cfoutput>"></td>
			</tr>
			<tr>
				<td width="18"></td>
				<td>合计: <span class="numeric"><cfoutput>#arrayLen(choosenArray)#</cfoutput></span> 门课程</td>
				<td align="center" width="40">预收</td>
				<td align="center" width="80"><span class="numeric bold"><cfoutput>#numberFormat(preCharged, "_.__")#</cfoutput></span></td>
				<cfif payCharged gt 0>
					<td align="center" width="80">重新学习</td>
					<td align="center" width="80"><span class="numeric bold"><cfoutput>#numberFormat(payCharged, "_.__")#</cfoutput></span></td>
				</cfif>
				<cfif paySecondCharged gt 0>
					<td align="center" width="60">双学位</td>
					<td align="center" width="80"><span class="numeric bold"><cfoutput>#numberFormat(paySecondCharged, "_.__")#</cfoutput></span></td>
				</cfif>
				<cfif payAssistCharged gt 0>
					<td align="center" width="40">辅修</td>
					<td align="center" width="80"><span class="numeric bold"><cfoutput>#numberFormat(payAssistCharged, "_.__")#</cfoutput></span></td>
				</cfif>
			</tr>
		</tbody>
	</table>
	
	
	<cfelse>
	<div class="systemNotice">
		<h3>学生没有选课</h3>
	</div>
</cfif>